﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Driver;
using System.Configuration;

namespace TMS.ProjectServiceImplement.DAL
{
    public class DataAccess
    {
        private static string connectionString;

        static DataAccess()
        {
            connectionString = ConfigurationManager.AppSettings["MangoDB_ConnectionString"];
            if (string.IsNullOrEmpty(connectionString))
            {
                connectionString = "mongodb://localhost/?safe=true";
            }
        }

        public static MongoCollection<T> GetPublishDB<T>(string tableName) where T : class, new()
        {
            var server = MongoServer.Create(connectionString);
            var database = server.GetDatabase("Project");
            var collection = database.GetCollection<T>(tableName);

            return collection;
        }
    }
}
